import java.net.*;
import java.io.*;

public class FileClient{
  public static void main (String [] args ) throws IOException {
    long start = System.currentTimeMillis();

    for(int files=0; files<20;files++)
    {
    Socket sock = new Socket("127.0.0.1",13267);
    System.out.println("Connecting...");


    	
    
    // receive file
    ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
    FileOutputStream fos = new FileOutputStream ("output.mp3"); //("output"+(files)+".mp3");
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    data myDataObject = new data(new byte[1]);
	try
	{
		myDataObject = (data)ois.readObject();
	}
	catch (ClassNotFoundException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

    byte [] mybytearray  = myDataObject.mybytes;


    bos.write(mybytearray, 0 ,mybytearray.length);
    bos.flush();
    long end = System.currentTimeMillis();
    System.out.println("The transfer took: " + (end-start) + " msec");
    
    bos.close();
    sock.close();
    }
  }
}

